//
//  KLCommentTableViewCell.m
//  KunLun
//
//  Created by Mac on 2017/11/28.
//  Copyright © 2017年 stoneobs@icloud.com. All rights reserved.
//

#import "KLCommentTableViewCell.h"
#import "STXingXIngView.h"
@interface KLCommentTableViewCell()
@property(nonatomic, strong) UIImageView                     *iconImageView;
@property(nonatomic, strong) STLabel                     *nameLable;
@property(nonatomic, strong) STLabel                     *timeLable;
@property(nonatomic, strong) STXingXIngView                     *xingxingView;
@property(nonatomic, strong) STLabel                     *commentLable;
@end
@implementation KLCommentTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self configSubView];
    }
    return self;
}
+ (CGFloat)cellHeight{
    return 100;
}
#pragma mark --subView
- (void)configSubView{
    self.iconImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 40, 40)];
    self.iconImageView.layer.cornerRadius = 20;
    self.iconImageView.clipsToBounds = YES;
    self.iconImageView.image = [UIImage imageNamed:@"touxiang"];
    [self addSubview:self.iconImageView];
    
    self.xingxingView = [[STXingXIngView alloc] initWithFrame:CGRectMake(0, 15, 120, 30) maxsNum:5];
    [self.xingxingView makeXingXingSelectedWithNum:2];
    self.xingxingView.right = UIScreenWidth - 10;
    [self addSubview:self.xingxingView];
    self.nameLable =  [[STLabel alloc] initWithFrame:CGRectMake(self.iconImageView.right + 10, 15, self.xingxingView.left - 20 - self.iconImageView.st_right, 30)
                                                text:@"stonoebs"
                                           textColor:KL_secendTextColor
                                                font:14
                                         isSizetoFit:NO
                                       textAlignment:NSTextAlignmentLeft];
    [self addSubview:self.nameLable];
    
    self.timeLable =  [[STLabel alloc] initWithFrame:CGRectMake(self.iconImageView.right + 10 , self.nameLable.bottom  +3, UIScreenWidth - 20 - self.iconImageView.st_right, 16)
                                                text:@"2017年11月28日10:33:24"
                                           textColor:KL_secendTextColor
                                                font:14
                                         isSizetoFit:NO
                                       textAlignment:NSTextAlignmentLeft];
    [self addSubview:self.timeLable];
    
    self.commentLable =  [[STLabel alloc] initWithFrame:CGRectMake(self.iconImageView.right + 10, self.timeLable.st_bottom + 5, UIScreenWidth - 20 - self.iconImageView.st_right, 40)
                                                   text:@"我在叽叽歪歪"
                                              textColor:KL_firstTextColor
                                                   font:15
                                            isSizetoFit:NO
                                          textAlignment:NSTextAlignmentLeft];
    self.commentLable.numberOfLines = 0;
    self.xingxingView.userInteractionEnabled = NO;
    [self addSubview:self.commentLable];
}
//- (void)setModel:(GHCommentModel *)model{
//    _model = model;
//    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.u_img] placeholderImage:GH_placeHoderImage];
//    NSDate * date = [NSDate dateWithTimeIntervalSince1970:[model.add_time integerValue]].st_localDate;
//    self.timeLable.text =  date.st_yyyyMMddhhmmssWithDate;
//    self.commentLable.text = model.content;
//    [NSString lableAutoAdjustheightWithLabel:self.commentLable];
//    model.height = self.commentLable.st_bottom + 20;
//}
-  (void)setCommentModel:(KLCommentModel *)commentModel{
    _commentModel = commentModel;
    
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:commentModel.user.header] placeholderImage:self.iconImageView.image];
    
    self.nameLable.text = commentModel.user.nickname;
    
    NSInteger num =  commentModel.level.integerValue;
    [self.xingxingView makeXingXingSelectedWithNum:num] ;
    
    self.commentLable.text = commentModel.comment;
    
    NSDate * date = [NSDate dateWithTimeIntervalSince1970:commentModel.created_at.integerValue].st_localDate;
    
    self.timeLable.text = date.st_yyyyMMddhhmmssWithDate;
    
    
    [NSString lableAutoAdjustheightWithLabel:self.commentLable];
    commentModel.height = 60 + 30 + self.commentLable.height;
}
@end
